home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / dpmigcc5.zip / RSX / SOURCE / ASM16 / FPU.ASM < prev    next >
Assembly Source File  |  1994-12-12  |  2KB  |  143 lines

  1. ;
  2. ; FPU.ASM (c) Rainer Schnitker 92,93
  3. ;
  4.  
  5. ;
  6. ; 387 utils
  7. ;
  8.  
  9.     .286
  10.     .model SMALL, C
  11.  
  12.     .data
  13.  
  14.     extrn    emu_entry:PWORD
  15.     extrn    emu_sel:WORD
  16.     extrn    emu_esp:DWORD
  17.     havei387    dw        0
  18.  
  19.     .code
  20.  
  21. ;
  22. ; DWORD emu_init( void ) : call emu387 to get copro struct
  23. ;
  24. ; emu should init exception vector 7
  25. ;
  26.     public C emu_init
  27. emu_init Proc C USES DI SI,
  28.     .386
  29.     push    gs
  30.     mov    eax,12345678H
  31.     mov    gs,emu_sel
  32.     mov    edx,emu_esp
  33.     call    pword ptr emu_entry
  34.     ; convert eax = copro-struct in dx:ax
  35.     mov    edx,eax
  36.     shr    edx,16
  37.     and    eax,dword ptr 0FFFFh
  38.     pop    gs
  39.     .286
  40.     ret
  41. emu_init endp
  42.  
  43. ;
  44. ; void emu_switch( WORD , WORD ) : call emu387, to change process status
  45. ;
  46.     public C emu_switch
  47. emu_switch PROC C \
  48.     used_math    :WORD , \
  49.     debugged    :WORD
  50.     .386
  51.     push    gs
  52.     mov    gs,emu_sel
  53.     movzx    ecx,used_math
  54.     movzx    edx,debugged
  55.     call    pword ptr emu_entry
  56.     pop    gs
  57.     .286
  58.     ret
  59. emu_switch endp
  60.  
  61. ;
  62. ; void do_fnsave( unsigned fpu_struct )
  63. ;
  64.     public C do_fnsave
  65. do_fnsave PROC C \
  66.     fpu_struct    :WORD
  67.  
  68.     .386
  69.     movzx    eax,word ptr fpu_struct
  70.     db 066H
  71.     fnsave    [eax]
  72.     fwait
  73.     .286
  74.     ret
  75. do_fnsave endp
  76.  
  77. ;
  78. ; void do_frstor( unsigned fpu_struct )
  79. ;
  80.     public C do_frstor
  81. do_frstor PROC C \
  82.     fpu_struct    :WORD
  83.  
  84.     .386
  85.     movzx    eax,word ptr fpu_struct
  86.     db 066H
  87.     frstor    [eax]
  88.     fwait
  89.     .286
  90.     ret
  91. do_frstor endp
  92.  
  93. ;
  94. ; void do_fninit(void)
  95. ;
  96.     public C do_fninit
  97. do_fninit PROC C
  98.     fninit
  99.     ret
  100. do_fninit endp
  101.  
  102.  
  103.     public C npx_installed
  104. npx_installed PROC C USES SI,
  105.  
  106.     fninit                    ; set SW,CW,..
  107.     mov    si, offset havei387
  108.     mov    word ptr [si],5a5ah
  109.     fnstsw    [si]                ; save SW
  110.     cmp    byte ptr [si],0         ; SW==0 ?
  111.     jne    no_i387
  112.  
  113.     fnstcw    [si]                ; save CW
  114.     mov    ax,[si]             ; check
  115.     and    ax,103fh            ;
  116.     cmp    ax,3fh                ; init ?
  117.     jne    no_i387
  118.  
  119.     fld1                    ; check for 387
  120.     fldz
  121.     fdiv
  122.     fld    st
  123.     fchs
  124.     fcompp
  125.     fstsw    [si]
  126.     mov    ax,[si]
  127.     sahf
  128.     je    no_i387
  129.     fninit                    ; 387 ok ,init
  130.     fnstcw    havei387
  131.     wait
  132.     and    havei387,0fffah
  133.     fldcw    havei387
  134.     mov    ax,1
  135.     jmp    short ende
  136. no_i387:
  137.     mov    ax,0
  138. ende:
  139.     ret
  140. npx_installed endp
  141.  
  142.     end
  143.